package mka.puzzle.cartesian;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.util.ArrayList;

import mka.puzzle.shape.Line;
import mka.puzzle.shape.Point;
import mka.puzzle.shape.Shape;

public class Axis extends Shape {
	/**
	 * Point
	 */
	private Point pointZero;

	/**
	 * Axis.
	 */
	private Line axisX;

	/**
	 * Axis.
	 */
	private Line axisY;

	/**
	 * Scale.
	 */
	private long scale;

	/**
	 * Length.
	 */
	private long length;

	/**
	 * Constructor (Axis(long length)).
	 * 
	 * Set center point of form is point zero.
	 */
	public Axis(long length) {
		Point begin = new Point(0, length / 2);
		Point end = new Point(length, length / 2);
		this.axisX = new Line(begin, end);

		Point beginY = new Point(length / 2, length);
		Point endY = new Point(length / 2, 0);
		this.axisY = new Line(beginY, endY);
	}

	/**
	 * Constructor (Axis(Point poinZero, long length)).
	 */
	public Axis(Point pointZero, long length) {
		this.pointZero = new Point(pointZero.getX(), pointZero.getY());
		
		Point beginX = new Point(this.pointZero.getX() - length / 2,
				this.pointZero.getY());
		Point endX = new Point(this.pointZero.getX() + length / 2,
				this.pointZero.getY());
		
		this.axisX = new Line(beginX, endX);

		Point beginY = new Point(this.pointZero.getX(), this.pointZero.getY()
				- length / 2);
		Point endY = new Point(this.pointZero.getX(), this.pointZero.getY()
				+ length / 2);
		
		this.axisY = new Line(beginY, endY);
	}

	public Line getAxisX() {
		return axisX;
	}

	public Line getAxisY() {
		return axisY;
	}

	public void drawAxis(Graphics g) {
		Graphics2D g2d = (Graphics2D) g;
		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
				RenderingHints.VALUE_ANTIALIAS_ON);
		g2d.setColor(Color.BLACK);
		g2d.drawLine((int) this.axisX.getPointBegin().getX(), (int) this.axisX
				.getPointBegin().getY(), (int) this.axisX.getPointEnd().getX(),
				(int) this.axisX.getPointEnd().getY());

		g2d.drawLine((int) this.axisY.getPointBegin().getX(), (int) this.axisY
				.getPointBegin().getY(), (int) this.axisY.getPointEnd().getX(),
				(int) this.axisY.getPointEnd().getY());
	}

	@Override
	public String getName() {
		return "Axis";
	}

	@Override
	public double getPerimeter() {
		return 0;
	}

	@Override
	public double getArea() {
		return 0;
	}

	@Override
	public ArrayList<Point> allPointBound() {
		return null;
	}

	@Override
	public ArrayList<Point> allPointShape() {
		return null;
	}

	@Override
	public void draw(Graphics g) {
		g.drawLine((int) this.getAxisX().getPointBegin().getX(), (int) this
				.getAxisX().getPointBegin().getY(), (int) this.getAxisX()
				.getPointEnd().getX(), (int) this.getAxisX().getPointEnd()
				.getY());

		g.drawLine((int) this.getAxisY().getPointBegin().getX(), (int) this
				.getAxisY().getPointBegin().getY(), (int) this.getAxisY()
				.getPointEnd().getX(), (int) this.getAxisY().getPointEnd()
				.getY());

	}
}
